using Microsoft.AspNetCore.Mvc;
using UniversalAdmin.Application.Dtos.Log;
using UniversalAdmin.Application.Services.Interfaces;

[ApiController]
[Route("api/[controller]")]
public class LogController : ControllerBase
{
    private readonly ILogService _service;
    public LogController(ILogService service) { _service = service; }

    [HttpPost]
    public async Task<IActionResult> Add([FromBody] CreateLogDto dto)
    {
        await _service.AddAsync(dto);
        return Ok();
    }

    [HttpPost("query")]
    public async Task<IActionResult> Query([FromBody] LogQueryDto dto)
    {
        var (total, items) = await _service.QueryAsync(dto);
        return Ok(new { total, items });
    }

    [HttpPost("export")]
    public async Task<IActionResult> Export([FromBody] LogQueryDto dto)
    {
        var bytes = await _service.ExportAsync(dto);
        return File(bytes, "text/csv", "操作日志.csv");
    }
} 